package mount // import "xemo.top/docker/docker/api/types/mount"
import "os"

// type 表示挂载的类型
// type represents the type of a mount
type Type string

// Type constants
const (
	// TypeBind 是挂载主机目录的类型
	// TypeBind is the type for mounting host dir
	TypeBind Type = "bind"
	// TypeVolume 是远程存储卷的类型
	// TypeVolume is the type for remote storage volumes
	TypeVolume Type = "volume"
	// TypeTmpfs 是用于挂载tmpfs的类型
	// TypeTmpfs is the type for mounting tmpfs
	TypeTmpfs Type = "tmpfs"
	// TypeNamedPipe 是用于安装Windows命名管道的类型
	// TypeNamedPipe is the type for mounting Windows named pipes
	TypeNamedPipe Type = "npipe"
)

// 传播表示挂载的传播
// Propagation represents the propagation of a mount\
type Propagation string

const (
	// PropagationRPrivate RPRIVATE
	PropagationRPrivate Propagation = "rprivate"
	// PropagationPrivate PRIVATE
	PropagationPrivate Propagation = "private"
	// PropagationRShared RSHARED
	PropagationRShared Propagation = "rshared"
	// PropagationShared SHARED
	PropagationShared Propagation = "shared"
	// PropagationRSlave RSLAVE
	PropagationRSlave Propagation = "rslave"
	// PropagationSlave SLAVE
	PropagationSlave Propagation = "slave"
)

// Mount represents a mount (volume)
type Mount struct {
	Type Type `json:",omitempty"`
	// Source指定装载的名称。根据装载类型，这可能是卷名或主机路径，甚至被忽略。tmpfs不支持Source (必须为空值)
	// Source specifies the name of the mount.Depending on mount type,this may be a volume name or a host path,or even ignored.Source is not supported for tmpfs (must be an empty value)
	Source        string         `json:",omitempty"`
	Target        string         `json:",omitempty"`
	ReadOnly      bool           `json:",omitempty"`
	Consistency   Consistency    `json:",omitempty"`
	BindOptions   *BindOptions   `json:",omitempty"`
	VolumeOptions *VolumeOptions `json:",omitempty"`
	TmpfsOptions  *TmpfsOptions  `json:",omitempty"`
}

// TmpfsOptions 定义特定于 “tmpfs” 类型的装入的选项
// TmpfsOptions defines options specific to mounts of type "tmpfs"
type TmpfsOptions struct {
	// Size设置tmpfs的大小，以字节为单位
	// Size sets the size of the tmpfs,in bytes
	//
	// 这将根据主机转换为操作系统特定的值。例如，在linux上，它将被转换为使用 'k'，'m' 或 'g' 语法。BSD虽然没有被docker广泛支持，但使用直接字节值。
	// This will be converted to an operating system specific value depending on the host.For example,on linux,it will be converted to use a 'k','m' or 'g' syntax.BSD,though not widely supported with docker,uses a straight byte value.
	//
	//Percentages are not supported
	SizeBytes int64 `json:",omitempty"`
	// Mode of the tmpfs upon creation
	Mode os.FileMode `json:",omitempty"`
	// TODO(stevvooe): There are several more tmpfs flags, specified in the
	// daemon, that are accepted. Only the most basic are added for now.
	//
	// From docker/docker/pkg/mount/flags.go:
	//
	// var validFlags = map[string]bool{
	// 	"":          true,
	// 	"size":      true, X
	// 	"mode":      true, X
	// 	"uid":       true,
	// 	"gid":       true,
	// 	"nr_inodes": true,
	// 	"nr_blocks": true,
	// 	"mpol":      true,
	// }
	//
	// Some of these may be straightforward to add, but others, such as
	// uid/gid have implications in a clustered system.
}

// VolumeOptions represents the options for a mount of type volume
type VolumeOptions struct {
	NoCopy       bool              `json:",omitempty"`
	Labels       map[string]string `json:",omitempty"`
	DriverConfig *Driver           `json:",omitempty"`
}

// Driver represents a volume driver.
type Driver struct {
	Name    string            `json:",omitempty"`
	Options map[string]string `json:",omitempty"`
}

// BindOptions 定义特定于 “bind” 类型的挂载的选项
// BindOptions defines options specific to mounts of type "bind"
type BindOptions struct {
	Propagation  Propagation `json:",omitempty"`
	NonRecursive bool        `json:",omitempty"`
}

// Consistency 表示装载的一致性要求
// Consistency represents the consistency requirements of a mount
type Consistency string

const (
	// ConsistencyFull 保证类似bind mount的一致性
	// ConsistencyFull guarantees bind mount-like consistency
	ConsistencyFull Consistency = "consistency"
	// ConsistencyCached 装载可以缓存读取数据和FS结构
	// ConsistencyCached mounts can cache read data and FS structure
	ConsistencyCached Consistency = "cached"
	// ConsistencyDelegated 装载可以缓存读取写入的数据和结构
	// ConsistencyDelegated mounts can cache read written data and structure
	ConsistencyDelegated Consistency = "delegated"
	// ConsistencyDefault 规定 “一致” 的行为，除非被覆盖
	// ConsistencyDefault provides "consistent" behavior unless overridden
	ConsistencyDefault Consistency = "default"
)
